// pages/clockin/clockin.js
var QQMapWX = require('../../../../utils/qqmap-wx-jssdk');
var config = require("../../../../utils/config")
var qqmapsdk = new QQMapWX({
	key: config.qq_key // 必填
});
var util = require("../../../../utils/util");
var timeid;
const {
	http
} = require("../../../../utils/apiutils");

import {
	getMore
} from '../../../../utils/tools'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		scrollH: 90,
		tabs: [{
			title: '考勤打卡',
			name: 1
		},
		{
			title: '打卡记录',
			name: 2
		}
		],
		tabActive: 1,
		active: 1,
		type: [],
		fileList: [],
		gwInfo: {},
		latitude: "",
		ds: "",
		time: util.formatTime(new Date()),
		longitude: "",
		dataList: [],
		lInfo: null,
		newTime: "",
		imgList: [],
		imgStr: [],
		spx: 0,
		jobData: null,
		dktype: {
			ds: true,
			tm: true,
		},
		sbsj: '',
		xbsj: '',
		pageNo: 1,
		hasMore: true,
		loading: false,
		pageSize: 10,
		recordList: [],
		workBc: [{
			status: 1,
			text: '白班'
		},
		{
			status: 2,
			text: '夜班'
		}
		],
		reddk: 0,
		dkrule: [],
		workindex: 0,
		startd: '',
		endd: ''
	},
	onLoad: function (options) {
		var that = this;
		let info = JSON.parse(decodeURIComponent(options.data))

		this.setData({
			gwInfo: info,
			workindex: options.workindex
		})
		this.getJobData(this.data.gwInfo.jobId)
		this.getRule()
	},
	getJobData: function (id) {

		var that = this;
		wx.showLoading({
			title: '加载中...',
		})
		http.getJobData(id,
			function (res) {
				wx.hideLoading()
				if (res.code == 0) {
					let db = res.data;
					that.setData({
						jobData: db
					})
				} else {
					wx.showToast({
						title: res.message,
						icon: "none",
					})
				}
			},
			function (err) {
				wx.hideLoading()
			})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		
		
	},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {
	},
	getRule() {
		let params = {
			jobId: this.data.gwInfo.jobId * 1
		}
		http.queryRulesInfo(params, res => {
			if (res.status == 200) {
				this.setData({
					dkrule: res.obj
				})
				this.checktime()
			}
		}, err => {
		})
	},
	checktime() {
		// 判断  当前时间 是否在打卡时间范围内
		let now = new Date().getTime();
		let a = util.formatTimexg(new Date()) + ' ' + this.data.dkrule[this.data.workindex].startWorkTime
		let b = util.formatTimexg(new Date()) + ' ' + this.data.dkrule[this.data.workindex].endWorkTime
		let start = new Date(a).getTime();
		let end = new Date(b).getTime();
		let errortime = 60 * 1000 * 30;
		this.setData({
			startd:util.getHHMM(start - errortime)+'-'+util.getHHMM(start + errortime),
			endd:util.getHHMM(end-errortime)+'-'+util.getHHMM(end+errortime)
		})
	},

})